package com.weixinli.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.weixinli.beans.Smile;
import com.weixinli.dao.ISmileDao;

@Repository("iSmileDao")
public class SmileDaoImpl implements ISmileDao {
	@Resource(name="sqlSession")
	private SqlSession sqlSession;
	
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	public int addSmile(Smile sm) {
		return sqlSession.insert("smileDao.addSmile", sm);
	}

	public int delSmile(Integer sid) {
		return 0;
	}

	public int modSmile(Smile sm) {
		return 0;
	}

	public List<Smile> getPageSmile(Integer pageNo, Integer pageSize) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("min",(pageNo-1)*pageSize );
		map.put("max", pageSize);
		return sqlSession.selectList("smileDao.findSmile", map);
	}

	public int getTotalSmile() {
		return sqlSession.selectOne("smileDao.totalSmile");
	}

	public int getTotalMySmile(int w_uid) {
		return sqlSession.selectOne("smileDao.totalMySmile",w_uid);
	}

	public List<Map<String, Object>> getOneSmile(String sid) {
		return sqlSession.selectList("smileDao.findSmileById", sid);
	}

	public List<Smile> getMySmile(Integer pageNo, Integer pageSize, Integer w_uid) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("min",(pageNo-1)*pageSize );
		map.put("max", pageSize);
		map.put("w_uid", w_uid);
		return sqlSession.selectList("smileDao.findMySmile", map);
	}

}
